#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <string.h>
static pthread_mutex_t mutex;
static void* thr(void *arg)
{
        while (1){
                pthread_mutex_lock(&mutex);
                printf("hello world\n");
                sleep(30);
                pthread_mutex_unlock(&mutex);       
        }
        return NULL;
}
int main(int argc, char const *argv[])
{
        pthread_t tid;
        pthread_mutex_init(&mutex,NULL);
        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);
        pthread_create(&tid,&attr,thr,NULL);
        while (1){
                int ret = pthread_mutex_trylock(&mutex);
                if(ret > 0){
                        printf("ret = %d, srrmsg: %s\n", ret,strerror(ret));
                }
                sleep(1);
        }
        pthread_attr_destroy(&attr);
        pthread_exit(NULL);
        return 0;
}
